<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="include :: header('项目关联事项详情')" />
    <th:block th:include="include :: jquery-smartwizard-css" />
    <th:block th:include="includeProject :: project-css" />
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <th:block th:include="includeProject :: projectInfo" />
                </div>
            </div>
        </div>
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox-title">
                        <h5 style="font: bold">关联事项</h5>
                        <div class="ibox-tools">
                            <a class="btn btn-success" href="javascript:void(0)" onclick="showMap()" style="color: white">项目进度"一张图"</a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="tabs-container">
                                    <ul class="nav nav-tabs">
                                        <li th:class="${labelStat.first}?'active':''" th:each="label,labelStat:${@dict.getType('eb_project_stage')}">
                                            <a data-toggle="tab" th:href="'#tab-' + ${label.dictValue}" aria-expanded="${labelStat.first}?'true':'false'" th:text="${label.dictLabel}"> </a>
                                        </li>
                                    </ul>
                                    <form class="form">
                                        <input type="hidden" id="projectId" name="projectId" th:value="${project.projectId}">
                                    <div class="tab-content">
                                        <div th:id="'tab-' + ${label.dictValue}" th:class="${labelStat.first}?'tab-pane active':'tab-pane'" th:each="label,labelStat:${@dict.getType('eb_project_stage')}">
                                            <div class="col-sm-12">
                                                <table class="table table-hover margin bottom">
                                                    <thead>
                                                    <tr>
                                                        <th>是否办理</th>
                                                        <th>事项名称</th>
                                                        <th>事项阶段</th>
                                                        <!--<th>承诺时限</th>-->
                                                        <th>状态</th>
                                                        <th>更新时间</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <tr th:if="${projectItem.stageItem.stageId} == ${label.dictValue}" th:each="projectItem : ${projectItems}" class="check">
                                                        <td>
                                                            <label class="toggle-switch switch-solid">
                                                                <input type="checkbox" th:checked="${projectItem.isClose == 0 ? true : false}" th:onchange="change([[${projectItem.projectItemId}]], this, [[${projectItem.projectItemStatus}]])">
                                                                <span></span>
                                                            </label>
                                                        </td>
                                                        <td th:text="${projectItem.stageItem.itemName}">-</td>
                                                        <td th:text="${label.dictLabel}">-</td>
                                                        <!--<td th:text="${projectItem.stageItem.itemDays}">-</td>-->
                                                        <td th:id="'statusTd' + ${projectItem.projectItemId}" th:text="${@dict.getLabel('eb_project_item_status',projectItem.projectItemStatus)}">-</td>
                                                        <td th:text="${#dates.format(projectItem.updateTime, 'yyyy-MM-dd HH:mm:ss')}">-</td>
                                                        <td th:id="'lastTd' + ${projectItem.projectItemId}" th:if="${projectItem.projectItemStatus} != 40"><a th:if="${projectItem.isClose} == 0" class="btn btn-success" href="javascript:void(0)" th:onclick="manage([[${projectItem.projectItemId}]])" >管理</a></td>
                                                        <td th:id="'lastTd' + ${projectItem.projectItemId}" th:if="${projectItem.projectItemStatus} == 40"><a th:if="${projectItem.isClose} == 0" class="btn btn-primary" href="javascript:void(0)" th:onclick="view([[${projectItem.projectItemId}]])" >查看</a> <a th:if="${projectItem.isClose} == 0" class="btn btn-success" href="javascript:void(0)" th:onclick="manage([[${projectItem.projectItemId}]])" >重新上传</a></td>
                                                    </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="includeProject :: project-js" />
    <script th:inline="javascript">
        // 合起项目基础信息
        $('#_projectInfo_link').trigger('click');

        $(".tab-content div:first").addClass("active");

        function manage(projectItemId) {
            var url = ctx + 'manage/itemdetail/manageItem/' + projectItemId;
            $.modal.open("事项进度管理", url, 800, ($(window).height() - 50), function (index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var flag = iframeWin.contentWindow.submitHandler(index, layero);
                if (flag) {
                    // location.reload();
                    $("#lastTd" + projectItemId).html("<a class=\"btn btn-primary\" href=\"javascript:void(0)\" onclick=\"view("+projectItemId+")\" >查看</a> <a class=\"btn btn-success\" href=\"javascript:void(0)\" onclick=\"manage("+projectItemId+")\" >重新上传</a>");
                    $("#statusTd" + projectItemId).html("已办结");
                }
            });
        }

        function view(projectItemId) {
            var url = ctx + 'manage/itemdetail/viewItem/' + projectItemId;
            $.modal.open("事项进度查看", url);
        }

        function showMap() {
            var projectId = $('#projectId').val();
            var url = ctx + 'manage/itemdetail/map/' + projectId;
            $.modal.openTab("工作进度\"一张图\"", url, function (index) {
                $.modal.close(index);
            });
        }

        function change(id, obj, status) {
            if (obj.checked) {
                $.modal.confirm("确认要开启办理吗？", function() {
                    $.operate.post(ctx + "manage/itemdetail/changeClose", { "projectItemId": id, "isClose": 0 }, function () {
                        if (status == 40) {
                            $("#lastTd" + id).html("<a class=\"btn btn-primary\" href=\"javascript:void(0)\" onclick=\"view("+id+")\" >查看</a> <a class=\"btn btn-success\" href=\"javascript:void(0)\" onclick=\"manage("+id+")\" >重新上传</a>");
                        } else {
                            $("#lastTd" + id).html("<a class=\"btn btn-success\" href=\"javascript:void(0)\" onclick=\"manage("+id+")\" >管理</a>");
                        }
                    });
                })
            } else {
                $.modal.confirm("确认要停止办理吗？", function() {
                    $.operate.post(ctx + "manage/itemdetail/changeClose", { "projectItemId": id, "isClose": 1 }, function () {
                        //location.reload();
                        $("#lastTd" + id).html("");
                    });
                })
            }
        }
    </script>
</body>
</html>